<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="coop.bancocredicoop.proyectos.gd.controller.documentosRecientes.
		DocumentosRecientesController" %>
<%@ page import="coop.bancocredicoop.proyectos.gd.domain.Document" %>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>

<%
	new DocumentosRecientesController().run(request);
%>

<%@ include file="../header.jsp" %>

    <script type="text/javascript" src="<%=request.getContextPath()%>/js/gs.js" rel="stylesheet"></script>
    <script type="text/javascript">
    function previewDocument(documentId) {
        console.debug(documentId);
        var baseUrl = '<%=request.getContextPath()%>/documento/abrirDesdeRepositorio';
        var url = baseUrl + '?documentId=' + documentId;
        var previewer = GD.DocumentPreviewer();
        previewer.previewDocument(url, 'Documento');
    }

	function loadDocumentDetail(documentId) {
		$('#detalleDocumentoModal').load("<%=request.getContextPath()%>/jsp/consultaDocumento/index.jsp",
				"id=" + documentId)
		$('#detalleDocumentoModal').modal('show')

		return false
	}
    </script>

    <div class="container">
    <div class="main-panel">
    <div class="panel panel-default">
    <div class="panel-heading"><h2>&Uacute;ltimos (<%=((List<Document>) request.getAttribute("listDocument")).size()%>) documentos guardados</h2>
    </div>
    <div class="panel-body">
    
   	<!-- BEGIN: flash messages -->
    <c:if test="${!sessionScope.hasErrors && sessionScope.successMessage != null}">
    	<div class="alert alert-success"><c:out value="${sessionScope.successMessage}" /></div> 
    </c:if>
    <c:if test="${sessionScope.hasErrors}">
    	<c:forEach items="${sessionScope.errorMessages}" var="message">
    	<div class="alert alert-danger"><c:out value="${message}" /></div>
    	</c:forEach> 
    </c:if>
    <% 
    	session.setAttribute("hasErrors", null);
    	session.setAttribute("successMessage", null);
    	session.setAttribute("errorMessages", null);
    %>
    <!-- END: flash messages -->

    <p><a class="btn btn-primary" role="button" href="<%=request.getContextPath()%>/documento/alta?gd=2">Cargar nuevo</a></p>
    <table class="table table-hover table-condensed">
        <thead>
            <tr>
              <th>Asociado</th>
              <th>Tipo de documento</th>
              <th>Caja AdeA</th>
              <th>Fecha de carga</th>
              <%--th>Vencimiento</th--%>
              <th>Versi&oacute;n</th>
              <th></th>
            </tr>
        </thead>
        <tbody>
        <% for (Document document : (List<Document>) request.getAttribute("listDocument")) { %>
            <tr>
                <td><%=document.getCustomer().getIdPersona() %> (<%=document.getCustomer().getName() %>, CUIT: <%=document.getCustomer().getCuit() %>)</td>
                <td><%=document.getDocumentType().getName() %></td>
                <td><%=document.getBox().getCajaId() %></td>
                <td><%=new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(document.getCreatedDate()) %></td>
                <%--td><g:formatDate format="dd-MM-yyyy" date="${document.validTo}"/></td--%>
                <td><%=document.getRealVersion() %></td>
				<td class="col-md-2">
					<button type="button" class="btn btn-default" onclick="previewDocument('<%=document.getId() %>')"><span class="glyphicon glyphicon-eye-open"></span></button>
					<a href="#" onclick="return loadDocumentDetail(<%=document.getId() %>)" class="btn btn-default"><span class="glyphicon glyphicon-info-sign"></span></a>
				</td>
            </tr>
        <% } %>
        </tbody>
    </table>

    </div>
    </div>
    </div>
    </div>
    <div class="modal fade" id="detalleDocumentoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

<%@ include file="../footer.jsp" %>